﻿using Microsoft.VisualStudio.DebuggerVisualizers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;

[assembly: DebuggerVisualizer(
        typeof(UTGenerator.Visualizador),
        typeof(VisualizerObjectSource),
        Target = typeof(decimal),
        Description = "Generate Unit Tests - UTGenerator")]

namespace UTGenerator
{
    public class Visualizador : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            if (windowService == null)
                throw new ArgumentNullException("windowService");
            if (objectProvider == null)
                throw new ArgumentNullException("objectProvider");

            object data = (decimal)objectProvider.GetObject();

            try
            {
                EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
                EnvDTE100.Solution4 sln = (EnvDTE100.Solution4)dte.Solution;

                UTGenerator.GeradorTestes.GerarTestes(data, dte, sln);

                System.Windows.Forms.MessageBox.Show("Unit test was generated successfully!");
            }
            catch (Exception ex)
            { 
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        public static void TestShowVisualizer(object objectToVisualize)
        {
            VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(Visualizador));
            visualizerHost.ShowVisualizer();
        }
    }
}

